layui.use(['layer','form','table','element'], function() {
    var layer = layui.layer, form = layui.form,table = layui.table,element=layui.element;
    var id = getUrlParam("id"),orderId="";
    show_loading();
    $.post(rurl('scm/expOrderPrice/detail'),{"id":id,"operation":"exp_order_price_examine"},function (res) {
       if(isSuccessWarnClose(res)){
           var data = res.data,orderPrice = data.orderPrice,members=data.members;
           orderId=orderPrice.orderId;
           table.render({
               elem: '#orderPriceMember',limit:5000,page:false
               ,cols: [[
                   {type:'numbers',title:'序号',width:45}
                   ,{field:'model',title:'型号',width:160 ,totalRowText: '合计'}
                   ,{field:'name',title:'名称',width:160}
                   ,{field:'brand',title:'品牌',width:160}
                   ,{field:'quantity',title:'数量',width:85,align:'money',totalRow: true}
                   ,{field:'unitName',title:'单位',width:50}
                   ,{field:'unitPrice',title:'单价',width:75,align:'right',templet:'#unitPriceTemp'}
                   ,{field:'totalPrice',title:'总价',width:85,align:'money',totalRow: true}
                   ,{field:'currencyName',title:'币制',width:65}
                   ,{field:'fluctuations',title:'波动率%',width:75,align:'right',templet:'#fluctuationsTemp'}
                   ,{field:'isImp',title:'进口记录',width:70,templet:'#isImpTemp'}
                   ,{field:'isNewGoods',title:'初次提交',width:70,templet:'#isNewGoodsTemp'}
                   ,{field:'spec',title:'规格描述'}
                   ,{field:'processLogs',title:'计算过程',width:160}
               ]]
               , data: members
           });
           formatTableData();
           $.each(members,function (i,o) {
               if(Math.abs(o.fluctuations)>=5){
                   var obj = $('div[fluctuations="'+o.id+'"]').parent().parent().parent();
                   obj.addClass('color-red');
               }
               if(o.isImp==false){
                   var obj = $('div[fluctuations="'+o.id+'"]').parent().parent().parent();
                   obj.addClass('color-orange');
               }
           });
       }
    });

    var $operationTaskBtn = $('.operation-task-btn'),
        taskArg = {'operation':'exp_order_price_examine','documentId':id,'documentClass':'ExpOrderPrice','newStatusCode':''};
    $operationTaskBtn.click(function () {
        var $that = $(this),needMemo = $that.attr('need-memo');
        if(!isEmpty(needMemo)){
            var $memo = $(needMemo);if(isEmpty($memo.val())){$memo.select();show_error($memo.attr('placeholder')||'必填项不能为空');return;}
            taskArg['memo'] = $memo.val();
        }else{
            taskArg['memo'] = $('#taskMemo').val();
        }
        taskArg['newStatusCode'] = $that.attr('status-code');

        show_loading();
        $.post(rurl('scm/expOrderPrice/examine'),taskArg,function (res) {
            if(isSuccess(res)){
                parent.reloadList();
                closeThisWin('操作成功');
            }
        });
    });

    var isLoad = false;
    element.on('tab(detailTab)', function(){
        var layId = this.getAttribute('lay-id');
        if(layId=="2"&&isLoad==false){
            isLoad = true;
            $('#orderDetail').attr({'src':rurl('order/priceexp/order-detail.html?orderId='+orderId)});
        }
    });
    $('.shortcut-selection').find('.layui-badge').click(function () {
        $('.shortcut-val').val($(this).text());
    });
    autoDetailContent();
    $(window).resize(function() {
        autoDetailContent();
    });
});
var $detailContent=$('#detail-content'),$tsfPageDetail = $('.tsf-page-detail');
function autoDetailContent(){
    $detailContent.css({'height':($tsfPageDetail.height()-37)+'px'});
}
var historyWin = null;
function showHistory(id) {
    layer.close(historyWin);
    historyWin = openwin(rurl('order/priceexp/history-list.html?id='+id),'历史价格',{shade:0,area: ['1016px', '300px']});
}